package com.itheima.HoneWork.homework02;

import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class TexeHero {
    public static void main(String[] args) throws IOException {
        BufferedWriter bw = null;
        FileReader fr=null;
        BufferedReader br=null;
        try {
            fr = new FileReader("E:\\img1\\hero.txt", Charset.forName("GBK"));
             br = new BufferedReader(fr);

            String lne;
            String tou = br.readLine();
            ArrayList<Hero> list = new ArrayList<>();
            while ((lne = br.readLine()) != null) {
                String[] split = lne.split(",+");
                Hero hero = new Hero(split[0], split[1], split[2], split[3]);
                list.add(hero);
            }
            br.close();
            Collections.sort(list, new Comparator<Hero>() {
                @Override
                public int compare(Hero o1, Hero o2) {
                    return Double.compare(o2.getXssy(), o1.getXssy());
                }
            });
            FileWriter fw = new FileWriter("E:\\img1\\hero.txt", Charset.forName("GBK"));
            bw = new BufferedWriter(fw);
            bw.write("姓名\t生存\t攻击\t效果\t新手适应分值");
            bw.newLine();
            for (Hero hero : list) {
                bw.write(hero.getName() + "\t" + hero.getSc() + "\t" + hero.getGj() + "\t" + hero.getXg() + "\t" + hero.getXssy());
                bw.newLine();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            bw.close();
            br.close();
        }

    }
}
